﻿namespace ACCOUNTING.LVY.Business
{
    using ACCOUNTING;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Data;
    using System.Runtime.CompilerServices;
    using System.Windows.Forms;

    public class clsConfig
    {
        private int mChonHangXuatTuDanhMuc = 0;
        private int mChoPhepAmQuy;
        private int mChoPhepXuatAm = 0;
        private string mCoQuanThue = "";
        private int mDaNhapTTCT = 0;
        private string mDonViChuQuan = "";
        private int mGhiSoDongThoi = 0;
        private int mGiaBanBaoGomThue = 0;
        private string mKhoaDonVi = "";
        private string mKhoaKho = "";
        private int mKhongXuatNoQuaDinhMuc = 0;
        private string mLoaiHoaDonInMacDinh = "";
        private string mLoaiInMacDinh = "";
        private string mMauHoaDonMacDinh = "";
        private string mMSTDonViChuQuan = "";
        private string mPhuongPhapGiaTonKho = "";
        private int mSoLienIn = 0;
        private string mThayDoiChungTu = "";
        private int mTheoDoiHanSuDung = 0;
        private int mTheoDoiLoHang = 0;
        private int mTheoDoiQuayKe = 0;
        private int mTheoDoiSoSeri = 0;
        private int mTheoDoiSoSeriKhiXuat = 0;

        public bool Load()
        {
            bool flag=false;
            try
            {
                string commandText = "SELECT * FROM HT_Config WHERE KhoaDonVi = '" + modGeneral.H_CLIENT + "'";
                IDataReader dataReader = DBHelper.ExecuteReader(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]);
                if (dataReader.Read())
                {
                    this.mTheoDoiLoHang = Conversions.ToInteger(modGeneral.GetValue(dataReader, 0, modGeneral.typeOfColumn.GetInt32));
                    this.mTheoDoiSoSeri = Conversions.ToInteger(modGeneral.GetValue(dataReader, 1, modGeneral.typeOfColumn.GetInt32));
                    this.mTheoDoiHanSuDung = Conversions.ToInteger(modGeneral.GetValue(dataReader, 2, modGeneral.typeOfColumn.GetInt32));
                    this.mTheoDoiQuayKe = Conversions.ToInteger(modGeneral.GetValue(dataReader, 3, modGeneral.typeOfColumn.GetInt32));
                    this.mThayDoiChungTu = Conversions.ToString(modGeneral.GetValue(dataReader, 4, modGeneral.typeOfColumn.GetString));
                    this.mPhuongPhapGiaTonKho = Conversions.ToString(modGeneral.GetValue(dataReader, 5, modGeneral.typeOfColumn.GetString));
                    this.mKhoaKho = Conversions.ToString(modGeneral.GetValue(dataReader, 6, modGeneral.typeOfColumn.GetString));
                    this.mGhiSoDongThoi = Conversions.ToInteger(modGeneral.GetValue(dataReader, 7, modGeneral.typeOfColumn.GetInt32));
                    this.mGiaBanBaoGomThue = Conversions.ToInteger(modGeneral.GetValue(dataReader, 8, modGeneral.typeOfColumn.GetInt32));
                    this.mKhoaDonVi = Conversions.ToString(modGeneral.GetValue(dataReader, 9, modGeneral.typeOfColumn.GetString));
                    this.mChoPhepXuatAm = Conversions.ToInteger(modGeneral.GetValue(dataReader, 10, modGeneral.typeOfColumn.GetInt32));
                    this.mTheoDoiSoSeriKhiXuat = Conversions.ToInteger(modGeneral.GetValue(dataReader, 11, modGeneral.typeOfColumn.GetInt32));
                    this.mKhongXuatNoQuaDinhMuc = Conversions.ToInteger(modGeneral.GetValue(dataReader, 12, modGeneral.typeOfColumn.GetInt32));
                    this.mChoPhepAmQuy = Conversions.ToInteger(modGeneral.GetValue(dataReader, 13, modGeneral.typeOfColumn.GetInt32));
                    this.mChonHangXuatTuDanhMuc = Conversions.ToInteger(modGeneral.GetValue(dataReader, 14, modGeneral.typeOfColumn.GetInt32));
                    this.mSoLienIn = Conversions.ToInteger(modGeneral.GetValue(dataReader, 15, modGeneral.typeOfColumn.GetInt32));
                    this.mLoaiInMacDinh = Conversions.ToString(modGeneral.GetValue(dataReader, 0x10, modGeneral.typeOfColumn.GetString));
                    this.mLoaiHoaDonInMacDinh = Conversions.ToString(modGeneral.GetValue(dataReader, 0x11, modGeneral.typeOfColumn.GetString));
                    this.mDaNhapTTCT = Conversions.ToInteger(modGeneral.GetValue(dataReader, 0x12, modGeneral.typeOfColumn.GetInt32));
                    this.mMauHoaDonMacDinh = Conversions.ToString(modGeneral.GetValue(dataReader, 0x13, modGeneral.typeOfColumn.GetString));
                    this.mDonViChuQuan = Conversions.ToString(modGeneral.GetValue(dataReader, 20, modGeneral.typeOfColumn.GetString));
                    this.mMSTDonViChuQuan = Conversions.ToString(modGeneral.GetValue(dataReader, 0x15, modGeneral.typeOfColumn.GetString));
                    this.mCoQuanThue = Conversions.ToString(modGeneral.GetValue(dataReader, 0x16, modGeneral.typeOfColumn.GetString));
                }
                dataReader.Close();
                flag = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public string NgayBatDauSuDung()
        {
            string commandText = " SELECT Top 1 IsNull(NamThang,'') As NamThang FROM GL_SoDuDauKyHangHoa";
            string str3 = LVYModule.ReturnIfNull(RuntimeHelpers.GetObjectValue(DBHelper.ExecuteScalar(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0])), "", modGeneral.TypeOfValue.Nothing).ToString().Trim();
            if (str3.Trim() != "")
            {
                return (str3 + "01");
            }
            commandText = " SELECT Top 1 IsNull(NamThang,'') As NamThang FROM GL_SoDuDauKyTaiKhoan";
            str3 = LVYModule.ReturnIfNull(RuntimeHelpers.GetObjectValue(DBHelper.ExecuteScalar(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0])), "", modGeneral.TypeOfValue.Nothing).ToString().Trim();
            if (str3.Trim() != "")
            {
                return (str3 + "01");
            }
            return "";
        }

        public bool Save()
        {
            bool flag2;
            IDataParameter[] commandParameters = new IDataParameter[0x17];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@TheoDoiLoHang", DbType.Double, ParameterDirection.Input, this.mTheoDoiLoHang);
                commandParameters[1] = DBHelper.createParameter("@TheoDoiSoSeri", DbType.Double, ParameterDirection.Input, this.mTheoDoiSoSeri);
                commandParameters[2] = DBHelper.createParameter("@TheoDoiHanSuDung", DbType.Double, ParameterDirection.Input, this.mTheoDoiHanSuDung);
                commandParameters[3] = DBHelper.createParameter("@TheoDoiQuayKe", DbType.Double, ParameterDirection.Input, this.mTheoDoiQuayKe);
                commandParameters[4] = DBHelper.createParameter("@ThayDoiChungTu", DbType.Int64, ParameterDirection.Input, this.mThayDoiChungTu);
                commandParameters[5] = DBHelper.createParameter("@PhuongPhapGiaTonKho", DbType.Int64, ParameterDirection.Input, this.mPhuongPhapGiaTonKho);
                commandParameters[6] = DBHelper.createParameter("@KhoaKho", DbType.Int64, ParameterDirection.Input, this.mKhoaKho);
                commandParameters[7] = DBHelper.createParameter("@GhiSoDongThoi", DbType.Double, ParameterDirection.Input, this.mGhiSoDongThoi);
                commandParameters[8] = DBHelper.createParameter("@GiaBanBaoGomThue", DbType.Double, ParameterDirection.Input, this.mGiaBanBaoGomThue);
                commandParameters[9] = DBHelper.createParameter("@KhoaDonVi", DbType.Int64, ParameterDirection.Input, this.mKhoaDonVi);
                commandParameters[10] = DBHelper.createParameter("@ChoPhepXuatAm", DbType.Double, ParameterDirection.Input, this.mChoPhepXuatAm);
                commandParameters[11] = DBHelper.createParameter("@TheoDoiSoSeriKhiXuat", DbType.Double, ParameterDirection.Input, this.mTheoDoiSoSeriKhiXuat);
                commandParameters[12] = DBHelper.createParameter("@KhongXuatNoQuaDinhMuc", DbType.Double, ParameterDirection.Input, this.mKhongXuatNoQuaDinhMuc);
                commandParameters[13] = DBHelper.createParameter("@ChoPhepAmQuy", DbType.Double, ParameterDirection.Input, this.mChoPhepAmQuy);
                commandParameters[14] = DBHelper.createParameter("@ChonHangXuatTuDanhMuc", DbType.Double, ParameterDirection.Input, this.mChonHangXuatTuDanhMuc);
                commandParameters[15] = DBHelper.createParameter("@SoLienIn", DbType.Double, ParameterDirection.Input, this.mSoLienIn);
                commandParameters[0x10] = DBHelper.createParameter("@LoaiInMacDinh", DbType.Int64, ParameterDirection.Input, this.mLoaiInMacDinh);
                commandParameters[0x11] = DBHelper.createParameter("@LoaiHoaDonInMacDinh", DbType.Int64, ParameterDirection.Input, this.mLoaiHoaDonInMacDinh);
                commandParameters[0x12] = DBHelper.createParameter("@DaNhapTTCT", DbType.Double, ParameterDirection.Input, this.mDaNhapTTCT);
                commandParameters[0x13] = DBHelper.createParameter("@LoaiHoaDonMacDinh", DbType.Int64, ParameterDirection.Input, this.mMauHoaDonMacDinh);
                commandParameters[20] = DBHelper.createParameter("@DonViChuQuan", DbType.Int64, ParameterDirection.Input, this.mDonViChuQuan);
                commandParameters[0x15] = DBHelper.createParameter("@MSTDonViChuQuan", DbType.Int64, ParameterDirection.Input, this.mMSTDonViChuQuan);
                commandParameters[0x16] = DBHelper.createParameter("@CoQuanThue", DbType.Int64, ParameterDirection.Input, this.mCoQuanThue);
                bool flag = DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.StoredProcedure, "HT_sp_Config", commandParameters) > 0;
                flag2 = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag2 = false;
                ProjectData.ClearProjectError();
                return flag2;
                ProjectData.ClearProjectError();
            }
            return flag2;
        }

        public int ChonHangXuatTuDanhMuc
        {
            get
            {
                return this.mChonHangXuatTuDanhMuc;
            }
            set
            {
                this.mChonHangXuatTuDanhMuc = value;
            }
        }

        public int ChoPhepAmQuy
        {
            get
            {
                return this.mChoPhepAmQuy;
            }
            set
            {
                this.mChoPhepAmQuy = value;
            }
        }

        public int ChoPhepXuatAm
        {
            get
            {
                return this.mChoPhepXuatAm;
            }
            set
            {
                this.mChoPhepXuatAm = value;
            }
        }

        public string CoQuanThue
        {
            get
            {
                return this.mCoQuanThue;
            }
            set
            {
                this.mCoQuanThue = value;
            }
        }

        public int DaNhapTTCT
        {
            get
            {
                return this.mDaNhapTTCT;
            }
            set
            {
                this.mDaNhapTTCT = value;
            }
        }

        public string DonViChuQuan
        {
            get
            {
                return this.mDonViChuQuan;
            }
            set
            {
                this.mDonViChuQuan = value;
            }
        }

        public int GhiSoDongThoi
        {
            get
            {
                return this.mGhiSoDongThoi;
            }
            set
            {
                this.mGhiSoDongThoi = value;
            }
        }

        public int GiaBanBaoGomThue
        {
            get
            {
                return this.mGiaBanBaoGomThue;
            }
            set
            {
                this.mGiaBanBaoGomThue = value;
            }
        }

        public string KhoaKhoMacDinh
        {
            get
            {
                return this.mKhoaKho;
            }
            set
            {
                this.mKhoaKho = value;
            }
        }

        public int KhongXuatNoQuaDinhMuc
        {
            get
            {
                return this.mKhongXuatNoQuaDinhMuc;
            }
            set
            {
                this.mKhongXuatNoQuaDinhMuc = value;
            }
        }

        public string LoaiHoaDonInMacDinh
        {
            get
            {
                return this.mLoaiHoaDonInMacDinh;
            }
            set
            {
                this.mLoaiHoaDonInMacDinh = value;
            }
        }

        public string LoaiInMacDinh
        {
            get
            {
                return this.mLoaiInMacDinh;
            }
            set
            {
                this.mLoaiInMacDinh = value;
            }
        }

        public string MauHoaDonMacDinh
        {
            get
            {
                return this.mMauHoaDonMacDinh;
            }
            set
            {
                this.mMauHoaDonMacDinh = value;
            }
        }

        public string MSTDonViChuQuan
        {
            get
            {
                return this.mMSTDonViChuQuan;
            }
            set
            {
                this.mMSTDonViChuQuan = value;
            }
        }

        public string PhuongPhapGiaTonKho
        {
            get
            {
                return this.mPhuongPhapGiaTonKho;
            }
            set
            {
                this.mPhuongPhapGiaTonKho = value;
            }
        }

        public int SoLienIn
        {
            get
            {
                return this.mSoLienIn;
            }
            set
            {
                this.mSoLienIn = value;
            }
        }

        public string ThayDoiChungTu
        {
            get
            {
                return this.mThayDoiChungTu;
            }
            set
            {
                this.mThayDoiChungTu = value;
            }
        }

        public int TheoDoiHanSuDung
        {
            get
            {
                return this.mTheoDoiHanSuDung;
            }
            set
            {
                this.mTheoDoiHanSuDung = value;
            }
        }

        public int TheoDoiQuayKe
        {
            get
            {
                return this.mTheoDoiQuayKe;
            }
            set
            {
                this.mTheoDoiQuayKe = value;
            }
        }

        public int TheoDoiSoLohang
        {
            get
            {
                return this.mTheoDoiLoHang;
            }
            set
            {
                this.mTheoDoiLoHang = value;
            }
        }

        public int TheoDoiSoSeri
        {
            get
            {
                return this.mTheoDoiSoSeri;
            }
            set
            {
                this.mTheoDoiSoSeri = value;
            }
        }

        public int TheoDoiSoSeriKhiXuat
        {
            get
            {
                return this.mTheoDoiSoSeriKhiXuat;
            }
            set
            {
                this.mTheoDoiSoSeriKhiXuat = value;
            }
        }
    }
}

